package com.qf.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
    public static void main(String[] args) {
        md5("123456");
    }
    public static String md5(String str){

            try {
                //创建一个密文类对象
                MessageDigest messageDigest = MessageDigest.getInstance("MD5");
                //根据传入的str加密
                messageDigest.update(str.getBytes());
                //获取保存再messageDigest当中加密的文件   获取的是一堆十进制数字
                byte[] digest = messageDigest.digest();
//                System.out.println(digest.toString());
                return new BigInteger(1, digest).toString(16);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }

        return null;
    }
}
